unit uEmpire;

interface

uses cuSimpleArrays;

type
  tEmpire = class( TObject )
  public
    empireRulerName       : string;

    empireDead            : boolean; //iff an empire reaches zero colonies then it dies off

    empirePopulation      : integer;
    empireMaxPopulation   : integer;
    empireTotalGrowth     : integer;
    empireTax             : integer;

    empireAstro           : TIntegerArray; // List of Astros the empire controls
    empireFleet           : TIntegerArray; // List of Fleets the empire controls
    empireShip            : TIntegerArray; // List of Ships the empire controls

    constructor Create(newRulerName:string);
    destructor Destroy(); override;
    procedure resetEmpire();
    procedure linkAstro(newAstroID:integer);
    procedure unlinkAstro(theAstroID:integer);
    procedure linkFleet(newFleetID:integer);
    procedure unlinkFleet(theFleetID:integer);
  end;

implementation

uses cuDebug, SysUtils;

constructor tEmpire.Create(newRulerName:string);
begin
  inherited Create();

  empireAstro  := TIntegerArray.Create('[TEmpire.empireAstro]');
  empireFleet  := TIntegerArray.Create('[TEmpire.empireFleet]');
  empireShip   := TIntegerArray.Create('[TEmpire.empireShip]');

  resetEmpire();
  empireRulerName := newRulerName;
end;

destructor TEmpire.Destroy();
begin
  resetEmpire();

  FreeAndNil( empireAstro  );
  FreeAndNil( empireFleet  );
  FreeAndNil( empireShip   );

  inherited;
end;

procedure TEmpire.resetEmpire();
begin
  empireRulerName       := '';

  empireDead            := FALSE;

  empirePopulation      := 0;
  empireMaxPopulation   := 0;
  empireTotalGrowth     := 0;
  empireTax             := 0;

  empireAstro.ClearArray('resetEmpire'); // List of Colonies the empire controls
  empireFleet.ClearArray('resetEmpire');  // List of Colonies the empire controls
  empireShip.ClearArray('resetEmpire');   // List of Colonies the empire controls
end;

procedure TEmpire.linkAstro(newAstroID:integer);
begin
  DevConsole.Print(LOG_DEBUG2, '[TEmpire  ] linkAstro - Linking astro '+IntToStr(newAstroID)+' to '+empireRulerName);

  empireAstro.addItem( newAstroID ) // List of Colonies the empire controls
end;
procedure TEmpire.unlinkAstro(theAstroID:integer);
begin
  //Remove the link from empire to colony.
  DevConsole.Print(LOG_DEBUG2, '[TEmpire  ] unlinkAstro - Unlinking Astro '+IntToStr(theAstroID)+' from '+empireRulerName);

  empireAstro.DeleteByValue( theAstroID );
end;

procedure TEmpire.linkFleet(newFleetID:integer);
begin
  DevConsole.Print(LOG_DEBUG2, '[TEmpire  ] linkFleet - Linking fleet '+IntToStr(newFleetID)+' to '+empireRulerName);

  empireFleet.addItem( newFleetID ) // List of Colonies the empire controls
end;
procedure TEmpire.unlinkFleet(theFleetID:integer);
begin
  DevConsole.Print(LOG_DEBUG2, '[TEmpire  ] unlinkFleet - Unlinking fleet '+IntToStr(theFleetID)+' to '+empireRulerName);

  empireFleet.DeleteByValue( theFleetID );
end;

end.
